cmake_minimum_required (VERSION 3.0)#版本
project (unix-lrean)                #项目名称

set(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}/../") #设置项目根目录

if(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
    set(DEBUG TRUE)
    #在命令行中使用cmake -DDEBUG=on，会进入这一行，C++代码中自动会有#define DEBUG
    add_definitions(-DDEBUG) #注意一定要有-D
    add_definitions(-D_DEBUG)
endif(CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))

#条件编译
if(UNIX)
    set(CMAKE_C_COMPILER gcc)
    set(CMAKE_CXX_COMPILER g++)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -g -fpic -fPIC")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -D_DEBUG -O0 -ggdb")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2")
endif(UNIX)

if(DEBUG)
    set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin/debug")
    set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin/debug/lib")
    #要连接的库的目录
    link_directories(${CMAKE_SOURCE_DIR}/lib/debug)
else()
    set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin/release")
    set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin/release/lib")
    #要连接的库的目录
    link_directories(${CMAKE_SOURCE_DIR}/lib/release)
endif(DEBUG)

link_directories(/usr/lib64/mysql)

#头文件目录
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(.)

#子项目路径，在上面的先处理

add_subdirectory(src)